


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Blinky</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.npc.ghost</a>
</div>

<h1>Coverage Summary for Class: Blinky (nl.tudelft.jpacman.npc.ghost)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Blinky</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/12)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman.npc.ghost;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import java.util.List;
<i class="no-highlight">4</i>&nbsp;import java.util.Map;
<i class="no-highlight">5</i>&nbsp;import java.util.Optional;
<i class="no-highlight">6</i>&nbsp;
<i class="no-highlight">7</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
<i class="no-highlight">8</i>&nbsp;import nl.tudelft.jpacman.board.Square;
<i class="no-highlight">9</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
<i class="no-highlight">10</i>&nbsp;import nl.tudelft.jpacman.level.Player;
<i class="no-highlight">11</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
<i class="no-highlight">12</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
<i class="no-highlight">13</i>&nbsp;
<i class="no-highlight">14</i>&nbsp;/**
<i class="no-highlight">15</i>&nbsp; * &lt;p&gt;
<i class="no-highlight">16</i>&nbsp; * An implementation of the classic Pac-Man ghost Shadow.
<i class="no-highlight">17</i>&nbsp; * &lt;/p&gt;
<i class="no-highlight">18</i>&nbsp; * &lt;p&gt;
<i class="no-highlight">19</i>&nbsp; * Nickname: Blinky. As his name implies, Shadow is usually a constant shadow on
<i class="no-highlight">20</i>&nbsp; * Pac-Man&#39;s tail. When he&#39;s not patrolling the top-right corner of the maze,
<i class="no-highlight">21</i>&nbsp; * Shadow tries to find the quickest route to Pac-Man&#39;s position. Despite the
<i class="no-highlight">22</i>&nbsp; * fact that Pinky&#39;s real name is Speedy, Shadow is actually the fastest of the
<i class="no-highlight">23</i>&nbsp; * ghosts because of when there are only a few pellets left, Blinky drastically
<i class="no-highlight">24</i>&nbsp; * speeds up, which can make him quite deadly. In the original Japanese version,
<i class="no-highlight">25</i>&nbsp; * his name is Oikake/Akabei.
<i class="no-highlight">26</i>&nbsp; * &lt;/p&gt;
<i class="no-highlight">27</i>&nbsp; * &lt;p&gt;
<i class="no-highlight">28</i>&nbsp; * &lt;b&gt;AI:&lt;/b&gt; When the ghosts are not patrolling in their home corners (Blinky:
<i class="no-highlight">29</i>&nbsp; * top-right, Pinky: top-left, Inky: bottom-right, Clyde: bottom-left), Blinky
<i class="no-highlight">30</i>&nbsp; * will attempt to shorten the distance between Pac-Man and himself. If he has
<i class="no-highlight">31</i>&nbsp; * to choose between shortening the horizontal or vertical distance, he will
<i class="no-highlight">32</i>&nbsp; * choose to shorten whichever is greatest. For example, if Pac-Man is four grid
<i class="no-highlight">33</i>&nbsp; * spaces to the left, and seven grid spaces above Blinky, he&#39;ll try to move up
<i class="no-highlight">34</i>&nbsp; * towards Pac-Man before he moves to the left.
<i class="no-highlight">35</i>&nbsp; * &lt;/p&gt;
<i class="no-highlight">36</i>&nbsp; * &lt;p&gt;
<i class="no-highlight">37</i>&nbsp; * Source: http://strategywiki.org/wiki/Pac-Man/Getting_Started
<i class="no-highlight">38</i>&nbsp; * &lt;/p&gt;
<i class="no-highlight">39</i>&nbsp; *
<i class="no-highlight">40</i>&nbsp; * @author Jeroen Roosen 
<i class="no-highlight">41</i>&nbsp; *
<i class="no-highlight">42</i>&nbsp; */
<b class="nc"><i class="no-highlight">43</i>&nbsp;public class Blinky extends Ghost {</b>
<i class="no-highlight">44</i>&nbsp;
<i class="no-highlight">45</i>&nbsp;    /**
<i class="no-highlight">46</i>&nbsp;     * The variation in intervals, this makes the ghosts look more dynamic and
<i class="no-highlight">47</i>&nbsp;     * less predictable.
<i class="no-highlight">48</i>&nbsp;     */
<i class="no-highlight">49</i>&nbsp;    private static final int INTERVAL_VARIATION = 50;
<i class="no-highlight">50</i>&nbsp;
<i class="no-highlight">51</i>&nbsp;    /**
<i class="no-highlight">52</i>&nbsp;     * The base movement interval.
<i class="no-highlight">53</i>&nbsp;     */
<i class="no-highlight">54</i>&nbsp;    private static final int MOVE_INTERVAL = 250;
<i class="no-highlight">55</i>&nbsp;
<i class="no-highlight">56</i>&nbsp;    /**
<i class="no-highlight">57</i>&nbsp;     * Creates a new &quot;Blinky&quot;, a.k.a. &quot;Shadow&quot;.
<i class="no-highlight">58</i>&nbsp;     *
<i class="no-highlight">59</i>&nbsp;     * @param spriteMap
<i class="no-highlight">60</i>&nbsp;     *            The sprites for this ghost.
<i class="no-highlight">61</i>&nbsp;     */
<i class="no-highlight">62</i>&nbsp;    // TODO Blinky should speed up when there are a few pellets left, but he
<i class="no-highlight">63</i>&nbsp;    // has no way to find out how many there are.
<i class="no-highlight">64</i>&nbsp;    public Blinky(Map&lt;Direction, Sprite&gt; spriteMap) {
<b class="nc"><i class="no-highlight">65</i>&nbsp;        super(spriteMap, MOVE_INTERVAL, INTERVAL_VARIATION);</b>
<i class="no-highlight">66</i>&nbsp;    }
<i class="no-highlight">67</i>&nbsp;
<i class="no-highlight">68</i>&nbsp;    /**
<i class="no-highlight">69</i>&nbsp;     * {@inheritDoc}
<i class="no-highlight">70</i>&nbsp;     *
<i class="no-highlight">71</i>&nbsp;     * &lt;p&gt;
<i class="no-highlight">72</i>&nbsp;     * When the ghosts are not patrolling in their home corners (Blinky:
<i class="no-highlight">73</i>&nbsp;     * top-right, Pinky: top-left, Inky: bottom-right, Clyde: bottom-left),
<i class="no-highlight">74</i>&nbsp;     * Blinky will attempt to shorten the distance between Pac-Man and himself.
<i class="no-highlight">75</i>&nbsp;     * If he has to choose between shortening the horizontal or vertical
<i class="no-highlight">76</i>&nbsp;     * distance, he will choose to shorten whichever is greatest. For example,
<i class="no-highlight">77</i>&nbsp;     * if Pac-Man is four grid spaces to the left, and seven grid spaces above
<i class="no-highlight">78</i>&nbsp;     * Blinky, he&#39;ll try to move up towards Pac-Man before he moves to the left.
<i class="no-highlight">79</i>&nbsp;     * &lt;/p&gt;
<i class="no-highlight">80</i>&nbsp;     */
<i class="no-highlight">81</i>&nbsp;    @Override
<i class="no-highlight">82</i>&nbsp;    public Optional&lt;Direction&gt; nextAiMove() {
<b class="nc"><i class="no-highlight">83</i>&nbsp;        assert hasSquare();</b>
<i class="no-highlight">84</i>&nbsp;
<i class="no-highlight">85</i>&nbsp;        // TODO Blinky should patrol his corner every once in a while
<i class="no-highlight">86</i>&nbsp;        // TODO Implement his actual behaviour instead of simply chasing.
<b class="nc"><i class="no-highlight">87</i>&nbsp;        Unit nearest = Navigation.findNearest(Player.class, getSquare());</b>
<b class="nc"><i class="no-highlight">88</i>&nbsp;        if (nearest == null) {</b>
<b class="nc"><i class="no-highlight">89</i>&nbsp;            return Optional.empty();</b>
<i class="no-highlight">90</i>&nbsp;        }
<b class="nc"><i class="no-highlight">91</i>&nbsp;        assert nearest.hasSquare();</b>
<b class="nc"><i class="no-highlight">92</i>&nbsp;        Square target = nearest.getSquare();</b>
<i class="no-highlight">93</i>&nbsp;
<b class="nc"><i class="no-highlight">94</i>&nbsp;        List&lt;Direction&gt; path = Navigation.shortestPath(getSquare(), target, this);</b>
<b class="nc"><i class="no-highlight">95</i>&nbsp;        if (path != null &amp;&amp; !path.isEmpty()) {</b>
<b class="nc"><i class="no-highlight">96</i>&nbsp;            return Optional.ofNullable(path.get(0));</b>
<i class="no-highlight">97</i>&nbsp;        }
<b class="nc"><i class="no-highlight">98</i>&nbsp;        return Optional.empty();</b>
<i class="no-highlight">99</i>&nbsp;    }
<i class="no-highlight">100</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
